package com.example.foodsy.controller;

import com.example.foodsy.utils.Result;
import com.example.foodsy.entity.Province;
import com.example.foodsy.service.ProvinceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 省行政区域信息表 前端控制器
 * </p>
 *
 * @author cgc
 * @since 2025-09-23
 */
@RestController
@RequestMapping("/province")
@CrossOrigin
public class ProvinceController {

    @Autowired
    private ProvinceService provinceService;

    /**
     * 查询所有省份
     * 响应：成功时返回省份列表（用Result.ok(data)）
     */
    @GetMapping("/listAll")
    public Result listProvinceAll() {
        try {
            List<Province> provinces = provinceService.listAll();
            return Result.ok(provinces); // 用ok(Object data)返回列表
        } catch (Exception e) {
            return Result.fail("查询省份失败：" + e.getMessage()); // 失败返回错误信息
        }
    }


}
